from django.urls import reverse
from rest_framework.test import APIClient
from video.models import Videos
from django.test import TestCase
from user.models import UserProfile
from video.models import Videos
from comment.models import Comment
from like.models import Like_Comment


class TestComment(TestCase):
    def setUp(self):
        self.user1 = UserProfile.objects.create_user(id=1, username='testuser1', password='123456456')
        self.user2 = UserProfile.objects.create_user(id=2, username='testuser2', password='123456456')
        self.user3 = UserProfile.objects.create_user(id=3, username='testuser3', password='123456456')
        self.video1 = Videos.objects.create(vid=1, title='test1', duration=10, mup=self.user1, type='1')
        self.video2 = Videos.objects.create(vid=2, title='test2', duration=10, mup=self.user1, type='2')
        self.video3 = Videos.objects.create(vid=3, title='test3', duration=10, mup=self.user1, type='2')

        self.comment1 = Comment.objects.create(cid=1, content='comment 1', user=self.user1, video=self.video1)
        self.comment2 = Comment.objects.create(cid=2, content='comment 2', user=self.user2, video=self.video1)

        self.likec1 = Like_Comment.objects.create(lcid=1, user=self.user2, comment=self.comment1, type=True)
        self.likec2 = Like_Comment.objects.create(lcid=2, user=self.user2, comment=self.comment2, type=False)

    def test_get_comment_sorted_by_time(self):
        url = reverse('comment-detail-time',
                      kwargs={'video_id': 1, 'num': 2, 'user_id': 1, 'already': '&', 'option': 0})
        responce = self.client.get(url)

        self.assertEqual(responce.status_code, 200)
        self.assertEqual(len(responce.data['comments']), 2)

    def test_get_comments_sorted_by_hot(self):
        url = reverse('comment-detail-time',
                      kwargs={'video_id': 1, 'num': 2, 'user_id': 1, 'already': '&', 'option': 1})
        response = self.client.get(url)

        self.assertEqual(response.status_code, 200)

        self.assertEqual(len(response.data['comments']), 2)


